package com.itheima.wemedia.controller;


import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.wemedia.dto.WmMaterialPageRequestDto;
import com.itheima.wemedia.pojo.WmMaterial;
import com.itheima.wemedia.service.WmMaterialService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.itheima.core.controller.AbstractCoreController;

/**
 * @version 1.0
 * @description <p>自媒体图文素材信息</p>
 * @package com.itheima.wemedia.controller
 */
@Api(value = "WmMaterialController", tags = "自媒体图文素材信息")
@RestController
@RequestMapping("/material")
public class WmMaterialController extends AbstractCoreController<WmMaterial> {

    private WmMaterialService wmMaterialService;

    @Autowired
    public WmMaterialController(WmMaterialService wmMaterialService) {
        super(wmMaterialService);
        this.wmMaterialService = wmMaterialService;
    }


    /**
     * 素材分页查询
     * @param dto
     * @return
     */
    @ApiOperation("素材分页搜索")
    @PostMapping("/list")
    public PageResultVo list(@RequestBody WmMaterialPageRequestDto dto) {
        PageResultVo pageResultVo = wmMaterialService.pageList(dto);
        return pageResultVo;
    }


    @ApiOperation("素材收藏")
    @GetMapping("/collect/{id}")
    private ResultVo collect(@PathVariable("id") Long id ){
        wmMaterialService.collect(id);
        return ResultVo.ok();
    }

    @ApiOperation("素材收藏")
    @GetMapping("/cancel_collect/{id}")
    private ResultVo cancelCollect(@PathVariable("id") Long id ){
        wmMaterialService.cancelCollect(id);
        return ResultVo.ok();
    }

    @ApiOperation("素材删除")
    @GetMapping("/del_picture/{id}")
    private ResultVo delete(@PathVariable("id") Long id ){
        wmMaterialService.delete(id);
        return ResultVo.ok();
    }

}

